package com.ruoyi.carShop.controller;

import com.ruoyi.carShop.domain.One;
import com.ruoyi.carShop.service.LoadService;
import com.ruoyi.carShop.service.MerchantCarService;
import com.ruoyi.carShop.service.OrderDetailsZhService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Author：张因丛
 * @Date ：2024/9/13 14:28
 */
@RestController
@CrossOrigin
@RequestMapping("/details")
public class OrderDetailsZhController extends BaseController {
    @Autowired
    private OrderDetailsZhService orderDetailsZhService;
    @Autowired
    private LoadService loadService;
    @Autowired
    private MerchantCarService merchantCarService;
    @RequestMapping("/couponzh")
    public List<One> selectOrderDetailsZhList() {
        //1 获取request对象
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes sra = (ServletRequestAttributes)attributes;
        HttpServletRequest request = sra.getRequest();
        //2 从请求头获取token
        String token = request.getHeader("token");
        int seller = loadService.getToken(token);
        return orderDetailsZhService.selectOrderDetailsZhList((long) seller);
    }

    @RequestMapping("/searchzh")
    public List<One> selectSearchZhList(@RequestBody Map<String ,Object> map) {
        //1 获取request对象
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes sra = (ServletRequestAttributes)attributes;
        HttpServletRequest request = sra.getRequest();
        //2 从请求头获取token
        String token = request.getHeader("token");
        Long seller = Long.valueOf(loadService.getToken(token));
        Object frontData = map.get("frontData");
        return orderDetailsZhService.selectSearchZhList(frontData,seller);
    }
}
